<?php
session_start();
//包含头
include '../PHP/head.php';
?>
<?php
//包含bootstrap的顶端按钮
include '../PHP/menu.php';
?>

<br />
<br />
<p class="text-center lead">校核后的澄清</p>
<?php
//接收操作
if (isset($_GET['sent'])) {
	$deviation_id = $_GET['deviation_id'];
	require_once ('../FNS/db_fns.php');
		
		$db = db_connect();
		
		$query="update deviation set status = '汇总' where id = '".$deviation_id."'";
		$result=$db->query ($query);
		if ($result){
			echo "<br />";
			echo "<p>汇总设置成功。</p>";
		}else{
			echo "<br />";
			echo"<p>汇总设置失败！</p>";
	
		$db->close();
		}
	
}




if (isset($_GET['project_id'])) {
//接收GET过来的project_id，从deviation表里搜出project_id的且status是'校核'的澄清
require_once ('../FNS/db_fns.php');

$project_id = $_GET['project_id'];

$db = db_connect();
$query="select projects.code as project_code, projects.name as project_name, projects.sale as sale_id, projects.entrust_date, users.name as sale_name from projects inner join users on projects.sale = users.id where projects.id = '".$project_id."'";
	
$result=$db->query ($query);
$num_result=$result->num_rows;
	
//拿出数据
$row=$result->fetch_assoc ();
$project_code = stripslashes ($row['project_code']);
$project_name = stripslashes ($row['project_name']);
$sale_name = stripslashes ($row['sale_name']);
$sale_id = stripslashes ($row['sale_id']);

	
$result->free();
	
//列出编号基本信息
echo "
	<br />
	<div class='row'>
		<div class='col-md-2'><p class='text-right'>报价编号：</p></div>
		<div class='col-md-2'><p>".$project_code."</p></div>
		<div class='col-md-2'><p class='text-right'>项目名称：</p></div>
		<div class='col-md-4'><p>".$project_name."</p></div>
		<div class='col-md-1'><p class='text-right'>销售：</p></div>
		<div class='col-md-1'><p>".$sale_name."</p></div>
	</div>
	<br />
";

$query="select deviation.id, deviation.ref, deviation.des, deviation.status, users.name as issue_name from deviation 
	inner join users on deviation.user_id = users.id 
	where deviation.project_id = '".$project_id."' order by deviation.status";
$result=$db->query ($query);
if (!$result) {
	echo "<br />";
	echo "<p>没有需要处理的偏离。</p>";
	echo "</div>";
	echo "</body>";
	$db->close();
exit;
}
$num_result=$result->num_rows;
//写表头
echo "<table class='table table-striped'>";
echo "<tr>";
	echo "<td align='center' class='info'><strong>客户要求</strong></td>";
	echo "<td align='center' class='info'><strong>偏离内容</strong></td>";
	echo "<td align='center' class='info'><strong>提出人</strong></td>";
	echo "<td align='center' class='info'><strong>状态</strong></td>";
	echo "<td align='center' class='info'><strong>操作</strong></td>";
echo "</tr>";



//循环编制表格
for ($i=0; $i < $num_result; $i++) {

	$row=$result->fetch_assoc ();
	
	$ref = stripslashes ($row['ref']);
	$des = stripslashes ($row['des']);
	$issue_name = stripslashes ($row['issue_name']);
	$status = stripslashes ($row['status']);
	$deviation_id = stripslashes ($row['id']);
	
	$link_sent = "../PHP/show_deviation_checked.php?deviation_id=".$deviation_id."&sent=1&project_id=".$project_id;
	
	echo "<tr>";
	echo "<td align ='center'>".$ref."</td>";
	echo "<td align ='center'>".$des."</td>";
	echo "<td align ='center'>".$issue_name."</td>";
	echo "<td align ='center'>".$status."</td>";
	echo "<td align='center'>";
		if ($status == '校核') {echo "<a class='btn btn-success btn-sm' href='".$link_sent."' role='button'>已汇总</a>";}
	echo "</td>";
	echo "</tr>";
	
}
echo "</table>";


$result->free();
$db->close();
}
?>




</div>
</body>
</html>